<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <form action="" id="register">
    <input type="text" name="username">
    <input type="text" name="username">
    <input type="text" name="id">
  </form>
  <button id='submit'>提交</button>


  <script src="../lib/jquery-3.1.1.min.js"></script>
  <script>
    // 为jquery添加提取form表单的方法
    $.fn.serializeForm = function () {
      var o = {};
      var a = this.serializeArray();
      a.map(function (item, index) {
        // 如果存在两个input的name相同,则转成一个数组 
        if (o[item.name] !== undefined) {
          if (!o[item.name].push) {
            o[item.name] = [o[item.name]];
          }
          o[item.name].push(item.value || '');
        } else {
          o[item.name] = item.value || ''
        }
      })
      return o;
    }

    $("#submit").on("click", function () {
      var a = $("#register").serializeForm()
      console.log(a);
      var a = ''
      console.log(a.push);
    })
  </script>
</body>

</html>